package com.wowo.day1;

import org.apache.ibatis.session.SqlSession;
import org.apache.ibatis.session.SqlSessionFactory;
import org.junit.After;
import org.junit.Before;
import org.junit.Test;

import java.io.IOException;
import java.util.Date;
import java.util.List;

public class UserTest2 {
    UserDao2 userDao2;
    SqlSession sqlSession;

    @Before
    public void init() throws IOException {
        SqlSessionFactory sqlSessionFactory = MyBatisUtil.getSqlSessionFactory();
        sqlSession = sqlSessionFactory.openSession();
        userDao2 = sqlSession.getMapper(UserDao2.class);
    }
    @Test
    public void insertUserTest(){
        userDao2.insertUser(new User("king","qwe",23,new Date()));
    }
    @Test
    public void selectUserById(){
        userDao2.selectUserById(49);
    }

    @Test
    public void updateUser(){
        User user = new User("qwsf","qwe",20,new Date());
        user.setId(51);
        userDao2.updateUser(user);
    }
    @Test
    public void deleteUser(){
        userDao2.deleteUser(44);

    }
    @Test
    public void getAll(){
       List<User> users = userDao2.getAll();
        System.out.println(users);
    }

    @After
    public void destory(){
        sqlSession.commit();
        sqlSession.close();
    }
}
